scroll thru listview

I have the following questions:

I have two buttons <<next>> and <<previous>>.

1. How to highlight a row in a listview
2. How to scroll thru the listview whenever I press the next or previous button and highlight changes accordingly.

Any hint is appreciated.

FZ
faisal.zahidi@boeing.com - Fri Aug 12 02:41:34 EDT 2011

Re: scroll thru listview
SystemAdmin - Fri Aug 12 07:08:06 EDT 2011

1. use the set function
2. you have to add a callback function to the button to move the selection
 

int NumItems = 6
int SelectedRow = 0
string ListItems[NumItems] = {"1", "2", "3", "4", "5", "6"}
 
DB MainDB = null
DBE ListView = null
DBE NextButton = null
DBE PrevButton = null
 
void GoToNext (DB db)
{
  // Item numbering in listview starts from zero
  if (SelectedRow < NumItems-1)    
    {
      SelectedRow++
      set(ListView, SelectedRow, true) 
    }
}
 
void GoToPrev (DB db)
{
  // Item numbering in listview starts from zero
  if (SelectedRow > 0)    
    {
      SelectedRow--
      set(ListView, SelectedRow, true) 
    }
}
 
 
MainDB = create("ListView Test")
ListView = listView(MainDB, 0, 100, 10,  ListItems)
NextButton = apply(MainDB, "Next row", GoToNext)
PrevButton = apply(MainDB, "Previous row", GoToPrev)
 
realize MainDB
 
// Insert column to show data
insertColumn(ListView,0,"Test column",100, iconNone) 
// Select the first row in listview
set(ListView, SelectedRow, true) 
 
show MainDB

Re: scroll thru listview
llandale - Sun Aug 14 19:47:13 EDT 2011

SystemAdmin - Fri Aug 12 07:08:06 EDT 2011

1. use the set function
2. you have to add a callback function to the button to move the selection
 

int NumItems = 6
int SelectedRow = 0
string ListItems[NumItems] = {"1", "2", "3", "4", "5", "6"}
 
DB MainDB = null
DBE ListView = null
DBE NextButton = null
DBE PrevButton = null
 
void GoToNext (DB db)
{
  // Item numbering in listview starts from zero
  if (SelectedRow < NumItems-1)    
    {
      SelectedRow++
      set(ListView, SelectedRow, true) 
    }
}
 
void GoToPrev (DB db)
{
  // Item numbering in listview starts from zero
  if (SelectedRow > 0)    
    {
      SelectedRow--
      set(ListView, SelectedRow, true) 
    }
}
 
 
MainDB = create("ListView Test")
ListView = listView(MainDB, 0, 100, 10,  ListItems)
NextButton = apply(MainDB, "Next row", GoToNext)
PrevButton = apply(MainDB, "Previous row", GoToPrev)
 
realize MainDB
 
// Insert column to show data
insertColumn(ListView,0,"Test column",100, iconNone) 
// Select the first row in listview
set(ListView, SelectedRow, true) 
 
show MainDB

If you display less rows (4) than exist (6)..
... change "100, 10" ... to ... "100, 4"
your code indeed scrolls nicely. That's nice to know.

The callbacks should "get" the selected row.

I notice when at the top or bottom your code correctly doesn't advance, but it also changes the dialog box context to the Next/Previous button, whereas when it does advance the context is inside the list view: when advancing the selected row is black, when not its grey. That will rarely matter but who knows.

void GoToNext (DB db)
{
  // Item numbering in listview starts from zero
  SelectedRow = get(ListView)
  if (SelectedRow < NumItems-1)    
    {
      SelectedRow++
    }
    set(ListView, SelectedRow, true) 
}

 

  • Louie